#pragma once


namespace Xm
{
	template <class Iterator,class Ref,class Ptr>
	struct __reverse_iterator
	{
		Iterator _cur;
		typedef __reverse_iterator<Iterator, Ref, Ptr> Riterator;

		__reverse_iterator(Iterator it)
			:_cur(it)
		{}
		
		Riterator operator++()
		{
			--_cur;
			return *this;
		}

		Riterator operator++(int)
		{
			Riterator it(*this);
			--_cur;
			return it;
		}

		Riterator operator--()
		{
			++_cur;
			return *this;
		}

		Riterator operator--(int)
		{
			Riterator it(*this);
			++_cur;
			return it;
		}

		Ref operator*()
		{
			auto tmp = _cur;
			--tmp;
			return *tmp;
		}

		Ptr operator->()
		{
			return &(operator*());
		}

		bool operator!=(const Riterator&  it)
		{
			return _cur != it._cur;
		}

		bool operator==(const Riterator& it)
		{
			return _cur == it._cur;
		}
	};
}